﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GroupDetail.aspx.cs" Inherits="CRMWeb.Pages.Group.GroupDetail" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>

<body>
    <form id="form1" runat="server">
        <div class="ftitle">Group Information</div>
        <div class="fitem">
            <label style="width: 130px;">Group Name:</label>
            <input id="txtgroupname" name="GroupName" class="easyui-validatebox" style="width: 200px;" />
        </div>
        <div class="fitem">
            <label style="width: 130px;">Description:</label>
            <input id="txtdescription" name="Description" class="easyui-validatebox" style="width: 500px;" />
        </div>
        <div class="fitem">
            <label style="width: 130px;">Type:</label>
            <select id="cmbtype" class="easyui-combobox" data-options="panelHeight:'auto'" name="GroupType">
                <option value="Application">Application</option>
                <option value="Client">Client</option>
            </select>
            <span id="spnColor">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <img alt="" src="../../Media/BlackColor.png" style="height: 16px; width: 20px" />
                Personal Purpose
        <img alt="" src="../../Media/RedColor.png" style="height: 16px; width: 20px" />
                Business Purpose
        <img alt="" src="../../Media/GreenColor.jpg" style="height: 16px; width: 20px" />
                Broker Form
        <img alt="" src="../../Media/DarkBlueColor.png" style="height: 16px; width: 20px" />
                Online Affiliate
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <label>Bold:</label>
                Property Owner
            </span>
        </div>
        <div class="fitem">
            <label style="width: 130px;"></label>
            <input id="rdo30days" type="radio" name="days" value="30" onchange="GetGroupData();" />
            <label style="width: 50px;">30 days</label>
            <input id="rdo90days" type="radio" name="days" value="90" onchange="GetGroupData();" />
            <label style="width: 50px;">90 days</label>
            <input id="rdoalldays" type="radio" name="days" value="ALL" onchange="GetGroupData();" />
            <label style="width: 50px;">ALL</label>

            <input type="hidden" id="hdnDesc" runat="server" />
            <input type="hidden" id="hdnType" runat="server" />
            <input type="hidden" id="hdnDays" runat="server" />

            <asp:button id="Button1" runat="server" onclick="Button1_Click" text=" Export to CSV "
                style="float: right; margin-right: 20px; height: 25px; width: auto; display: inline-block; color: #FFFFFF; font-size: 12px; font-family: Arial; background-color: #1A7BC9; border: 1px solid #1A7BC9;" />

        </div>
        <br />

        <div class="fitem" id="applicationGrid">
            <table id="dgGroupApp" title="Group - Application" style="width: auto;" autorowheight="true" remotesort="true"
                rownumbers="true" fitcolumns="true" singleselect="true" data-options="pagination:true,pageSize:20">
                <thead>
                    <tr>
                        <th rowspan="2" field="app_id" width="25" sortable="true" data-options="formatter:cellFormatStyler">App. No</th>
                        <th field="applicant1" width="43" sortable="true" data-options="formatter:cellFormatStyler">First Applicant</th>
                        <th field="SecondApplicant" width="43" sortable="true" data-options="formatter:cellFormatStyler">Second Applicant</th>
                        <th rowspan="2" field="DesiredAmount" width="25" sortable="true" data-options="formatter:ReplaceNumberWithCommas">Desired</th>
                        <th rowspan="2" field="OfferedAmount" width="25" sortable="true" data-options="formatter:ReplaceNumberWithCommas">Offered</th>
                        <th rowspan="2" field="app_result" width="70" sortable="true" data-options="formatter:cellFormatStyler">Last Result</th>
                        <th rowspan="2" field="CreatedDate" width="30" sortable="true" data-options="formatter:formatDate">Create Date</th>
                        <th rowspan="2" field="EditDate" width="30" sortable="true" data-options="formatter:formatDate">Edit Date</th>
                        <th rowspan="2" field="applicationprofileid" width="20" sortable="true" data-options="formatter:formatApplicationProfile">App. Prof.</th>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="fitem" id="clientGrid">
            <table id="dgGroupClient" class="easyui-datagrid" title="Group - Client" style="width: auto;" autorowheight="true" remotesort="true"
                rownumbers="true" fitcolumns="true" singleselect="true" data-options="pagination:true,pageSize:20">
                <thead>
                    <tr>
                        <th field="ContactID" width="30" sortable="true" data-options="formatter:cellFormatStyler">Client No</th>
                        <th field="ClientName" width="80" sortable="true" data-options="formatter:cellFormatStyler">Full Name</th>
                        <th field="DateBirth" width="50" data-options="formatter:formatDate" sortable="true">Birth Date</th>
                        <th field="State" width="30" sortable="true" data-options="formatter:cellFormatStyler">State</th>
                        <th field="client_CreateDate" width="50" data-options="formatter:formatDate" sortable="true">Create Date</th>
                        <th field="client_EditDate" width="50" data-options="formatter:formatDate" sortable="true">Edit Date</th>
                        <th field="clientprofileid" width="20" sortable="true" data-options="formatter:formatApplicationProfile">Client Prof. </th>
                    </tr>
                </thead>
            </table>
        </div>
    </form>

    <script type="text/javascript">
        var setDefultRadio = true;
        $(document).ready(function () {
            GetGroupData();
        });
        $("#Button1").mouseover(function () {
            $("#Button1").css("background-color", "#9CC8F7");
            $("#Button1").css("color", "#404040");
        });
        $("#Button1").mouseout(function () {
            $("#Button1").css("background-color", "#1A7BC9");
            $("#Button1").css("color", "#FFFFFF");
        });

        function GetGroupData() {
            $('#hdnDays').val($('input[name="days"]:checked').val());

            $.ajax({
                url: '/WebServices/Group/Group.ashx?method=GetGroupDetail',
                contentType: "application/json; charset=utf-8",
                data: { GroupID: $('#hdnGroupID').val() },
                success: function (data) {
                    $.each(eval(data.replace(/[\r\n]/, '')), function (i, rec) {
                        $('#txtgroupname').val(rec.GroupName);
                        $('#hdnDesc').val(rec.Description);
                        var desc = formatedescription(rec.Description);
                        $('#txtdescription').val(desc);
                        $('#cmbtype').combobox('setValue', rec.GroupType);

                        $('#hdnType').val(rec.GroupType);

                        if (rec.GroupType == 'Application' || rec.GroupType == 'Direct Application') {
                            if (setDefultRadio == true)
                                document.getElementById("rdo30days").checked = true;

                            $('#spnColor').show();
                            $('#Button1').hide();

                            setDefultRadio = false;
                            $('#dgGroupApp').datagrid({
                                url: '/WebServices/Group/Group.ashx?method=GetGroupDataFromQuery&Type=' + rec.GroupType + '&Description=' + encodeURIComponent(rec.Description) + '&GroupName=' + $('#hdnGroupNameForPriorityQueue').val() + '&Days=' + $('input[name="days"]:checked').val(),
                                onDblClickRow: function (index, rowdata) {
                                    window.location.href = "/Pages/Application/ApplicationDetail.aspx?app_id=" + rowdata.app_id;
                                },
                                onSortColumn: function (sort, order) {
                                    quickSearchApp(sort + '  ' + order, rec.GroupType);
                                }
                            });
                            var opts = $('#dgGroupApp').datagrid('options');
                            opts.pageNumber = 1;
                            $('#applicationGrid').show();
                            $('#clientGrid').hide();
                        }
                        else if (rec.GroupType == 'Client' || rec.GroupType == 'Direct Client') {

                            if (setDefultRadio == true)
                                document.getElementById("rdoalldays").checked = true;

                            $('#applicationGrid').hide();
                            $('#spnColor').hide();
                            $('#Button1').show();
                            $('#clientGrid').show();
                            setDefultRadio = false;
                            $('#dgGroupClient').datagrid({
                                url: '/WebServices/Group/Group.ashx?method=GetGroupDataFromQuery&Type=' + rec.GroupType + '&Description=' + encodeURIComponent(rec.Description) + '&GroupName=' + $('#hdnGroupNameForPriorityQueue').val() + '&Days=' + $('input[name="days"]:checked').val(),
                                onDblClickRow: function (index, rowdata) {
                                    window.location.href = "/Pages/Contact/ContactDetail.aspx?contact_id=" + rowdata.ContactID;
                                },
                                onSortColumn: function (sort, order) {
                                    quickSearchClient(sort + '  ' + order, rec.GroupType);
                                }
                            });

                            var opts = $('#dgGroupClient').datagrid('options');
                            opts.pageNumber = 1;
                        }
                    });
                }
            });
        }

        function quickSearchApp(sortText, groupType) {
            $('#dgGroupApp').datagrid({
                url: '/WebServices/Group/Group.ashx?method=GetGroupDataFromQuery&Type=' + groupType + '&Description=' + encodeURIComponent($('#hdnDesc').val()) + '&GroupName=' + $('#hdnGroupNameForPriorityQueue').val() + '&Days=' + $('input[name="days"]:checked').val() + '&sortCondition=' + sortText
            });

        }
        function quickSearchClient(sortText, groupType) {
            $('#dgGroupClient').datagrid({
                url: '/WebServices/Group/Group.ashx?method=GetGroupDataFromQuery&Type=' + groupType + '&Description=' + encodeURIComponent($('#hdnDesc').val()) + '&GroupName=' + $('#hdnGroupNameForPriorityQueue').val() + '&Days=' + $('input[name="days"]:checked').val() + '&sortCondition=' + sortText
            });

        }
        function ReplaceNumberWithCommas(yourNumber, row) {
            if (yourNumber != null && yourNumber != '') {
                //Seperates the components of the number
                var components = yourNumber.toString().split(".");
                //Comma-fies the first part
                components[0] = components[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                //Combines the two sections
                return cellFormatStyler("$" + components.join("."), row);
            }
        }
        function formatApplicationProfile(value, row) {
            if ($('#cmbtype').combobox('getValue') == 'Application' || $('#cmbtype').combobox('getValue') == 'Direct Application') {
                return "<a href='/Pages/Application/ApplicationDetail.aspx?app_id=" + row.applicationprofileid + "' target='_blank' style='cursor:pointer'>View</a>";
            }
            else if ($('#cmbtype').combobox('getValue') == 'Client' || $('#cmbtype').combobox('getValue') == 'Direct Client') {
                return "<a href='/Pages/Contact/ContactDetail.aspx?contact_id=" + row.clientprofileid + "' target='_blank' style='cursor:pointer'>View</a>";
            }
        }
        function cellFormatStyler(value, row) {
            if ($('#cmbtype').combobox('getValue') == 'Application') {
                if (value == null)
                    value = '';

                if (row.PurposeSummary == 'Business' && row.amoutProperties != 0 && row.ReferrerVal != null && row.ReferrerVal != '')
                    return '<span style="font-weight:bold;color:#008000;">' + value + '</span>';
                if (row.PurposeSummary == 'Business' && row.ReferrerVal != null && row.ReferrerVal != '')
                    return '<span style="color:#008000;">' + value + '</span>';

                if (row.PurposeSummary == 'Personal' && row.amoutProperties != 0 && row.ReferrerVal != null && row.ReferrerVal != '')
                    return '<span style="font-weight:bold;color:#000084;">' + value + '</span>';
                if (row.PurposeSummary == 'Personal' && row.ReferrerVal != null && row.ReferrerVal != '')
                    return '<span style="color:#000084;">' + value + '</span>';

                if (row.PurposeSummary == 'Personal' && row.amoutProperties != 0)
                    return '<span style="font-weight:bold;color:#000000;">' + value + '</span>';
                if (row.PurposeSummary == 'Business' && row.amoutProperties != 0)
                    return '<span style="font-weight:bold;color:#ff0000;">' + value + '</span>';

                if (row.PurposeSummary == 'Personal')
                    return '<span style="color:#000000;">' + value + '</span>';
                if (row.PurposeSummary == 'Business')
                    return '<span style="color:#ff0000;">' + value + '</span>';
                else
                    return value;
            }
            else
                return value;
        }
        function formatDate(value, row) {
            var date = null;
            if (value == null)
                date = new Date();
            else
                date = new Date(value);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var month = '';
            switch (m) {
                case 1:
                    month = 'Jan';
                    break;
                case 2:
                    month = 'Feb';
                    break;
                case 3:
                    month = 'Mar';
                    break;
                case 4:
                    month = 'Apr';
                    break;
                case 5:
                    month = 'May';
                    break;
                case 6:
                    month = 'Jun';
                    break;
                case 7:
                    month = 'Jul';
                    break;
                case 8:
                    month = 'Aug';
                    break;
                case 9:
                    month = 'Sep';
                    break;
                case 10:
                    month = 'Oct';
                    break;
                case 11:
                    month = 'Nov';
                    break;
                case 12:
                    month = 'Dec';
                    break;
            }
            var d = date.getDate();
            return cellFormatStyler((d < 10 ? ('0' + d) : d) + ' ' + month + ' ' + y, row);
        }
        function formatedescription(value) {
            var str = new String(value);
            var str_arr = str.split("where");
            str = str_arr[1];
            str = str.replace(/=/gi, ' equals to ');
            str = str.replace(/like/gi, ' contains ');
            str = str.replace(/%/gi, '');
            str = str.replace(/>/gi, ' greater than ');
            str = str.replace(/</gi, ' less than ');
            return str;
        }
    </script>

</body>
</html>
